// pages/enter/enter.js
var requestutil = require('../../utils/request.js')
var util = require('../../utils/util.js')
import config from '../../utils/config.js'
var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:null,
    sex: '男',
    birthday:"",
    parent:null,
    phone:null,
    address:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideShareMenu({

    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    // let that=this;
    // var shareParam = "id={0}";
    // let title=null;
    // if (that.data.trainingBase)
    // {
    //   shareParam = String.format(shareParam, that.data.trainingBase.id);
    //   title = that.data.trainingBase.tnSubName ? that.data.trainingBase.tnSubName:"";
    // }else
    // {
    //   shareParam = String.format(shareParam, that.data.id);
    //   title = "";
    // }
    // return {
    //   title: title,
    //   path: '/pages/enter/enter?' + shareParam,
    //   success: function (res) {
    //     // 转发成功
    //   },
    //   fail: function (res) {
    //     // 转发失败
    //   }
    // }
  },
  enter:function()
  {
    let that = this
    console.info("宝宝姓名：" + that.data.contactName)
    if (util.isStringEmpty(that.data.name)) {
      wx.showToast({
        title: '请输入宝宝姓名!',
        icon: 'none'
      });
      return;
    }

    if (util.isStringEmpty(that.data.birthday)) {
      wx.showToast({
        title: '请选择宝宝出生日期!',
        icon: 'none'
      });
      return;
    }

    if (util.isStringEmpty(that.data.parent)) {
      wx.showToast({
        title: '请输入家长姓名!',
        icon: 'none'
      });
      return;
    }

    if (util.isStringEmpty(that.data.phone)) {
      wx.showToast({
        title: '请输入联系电话电话!',
        icon: 'none'
      });
      return;
    }

    if (util.isStringEmpty(that.data.address)) {
      wx.showToast({
        title: '请输入住址!',
        icon: 'none'
      });
      return;
    }



    var param = {};

    param.name = that.data.name;
    param.sex = that.data.sex;
    param.birthday = that.data.birthday;
    param.pname = that.data.parent;
    param.phone = that.data.phone;
    param.address = that.data.address;
    param.userId = app.globalData.shouerUser.userId;

    requestutil.sendRequest("queryUserQrCode", param, function (res){
      
      if (res.data.errorCode >= 0)
      {
        console.info("提交就诊信息成功!");
        var param = "url={0}";
        param = String.format(param, res.data.qrCodeFullUrl);
        wx.redirectTo({ url: '/pages/entersuccess/entersuccess?' + param});
      }else
      {
        wx.showToast({
          title: res.data.errorMsg,
          icon: 'none'
        })
      }

    },function()
    {
      console.error("提交就诊信息失败");
      //回调登录失败方法
      wx.showToast({
        title: '网络异常 提交就诊信息失败!',
        icon: 'none'
      })
    })

  },
  //宝宝姓名
  bindNameInput: function (e) {
    this.setData({
      name: e.detail.value
    })
  },
  //性别
  radioChange: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    this.setData({
      sex: e.detail.value
    });
  },
  //联系电话
  bindParentInput: function (e) {
    this.setData({
      parent: e.detail.value
    })
  },
  //联系电话
  bindPhoneInput: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  //地址
  bindAddressInput: function (e) {
    this.setData({
      address: e.detail.value
    })
  },
  //  点击日期组件确定事件  
  bindDateChange: function (e) {
    this.setData({
      birthday: e.detail.value
    })
  },  
  
})